package com.zh.analysis.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zh.analysis.service.MeasureService;
import org.springframework.stereotype.Service;


/**
 * 体征检测设备
 */
@Service
public class MeasureServiceImpl implements MeasureService {


    /**
     * 血压
     *
     * @param data 90mmHg<高压<140mmHg、60mmHg<低压<90mmHg、心率：60～100次/分
     *             {T=2838,P=997,H=5115}
     */
    @Override
    public JSONObject sphygmomanometer(String data) {
        double g = Double.parseDouble(data.split(",")[0]);
        double d = Double.parseDouble(data.split(",")[1]);
        double x = Double.parseDouble(data.split(",")[2]);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("g", g);
        jsonObject.put("d", d);
        jsonObject.put("x", x);
        StringBuffer message=new StringBuffer();
        message.append("高压:"+g);
        message.append("  低压:"+d);
        message.append("  心跳:"+x);
        if (g < 90 || g > 140 || d < 60 || d > 90 || x < 60 || x > 100) {
            jsonObject.put("anomalies",1);
        }else{
            jsonObject.put("anomalies",0);
        }

        jsonObject.put("message",message.toString());
        return jsonObject;
    }

    /**
     * 血氧
     *
     * @param data "deviceData":"112,99"
     */
    @Override
    public JSONObject oximeter(String data) {
        Double oximeter = Double.parseDouble(data.split(",")[0]);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("oximeter", oximeter);
        if (oximeter < 94) {
            jsonObject.put("anomalies",1);
        }else{
            jsonObject.put("anomalies",0);
        }
        jsonObject.put("message", "血氧值是"+oximeter);
        return jsonObject;
    }

    /**
     * 耳温枪
     *
     * @param data
     */
    @Override
    public JSONObject thermometer(String data) {
        double her = Double.parseDouble(data);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("her", her);
        if (her < 36.1 || her > 37) {
            jsonObject.put("anomalies",1);
        }else{
            jsonObject.put("anomalies",0);
        }
        jsonObject.put("message", "当前温度:"+her);
        return jsonObject;
    }
}
